#include <REG2051.H> 
#define b1 P3_7
#define b2 P3_3
#define b3 P3_4
#define b4 P3_2
#define mode P3_0
unsigned char font1[10]={0x14,0xd7,0x4c,0x45,0x87,0x25,0x24,0x57,0x04,0x05};
void delayQuet()
{
	unsigned char i,j;
	for(i =0;i<100;i++)
		for(j =0;j<10;j++){};		
} 
void quet()
{							      
	/////////////////////
	if(mode)
	{			
		P1=font1[(TH1*256+TL1)/1000];
		b1 = 0;
		delayQuet();
		b1=1;
	}
	else b1=1;
	///////////////////	
	P1=font1[((TH1*256+TL1)/100)%10]&0xfb;
	b2=0;	
	delayQuet();
	b2=1;
	//////////////////	
	P1=font1[((TH1*256+TL1)/10)%10];
	b3=0;
	delayQuet();
	b3=1;
	/////////////////
	P1=font1[(TH1*256+TL1)%10];
	b4=0;
	delayQuet();
	b4=1;
	////////////////
}	
void main()
{	
	bit temp;
	P3_5=1;	
	temp = P3_0;
	TMOD = 0x50;
	TH1=0x00;
	TL1=0x00;;
	TR1=1;
	while(1)
	{	
		if(mode && (TH1*256+TL1)>=9999)
		{
			 TR1=0;
			 TH1= 0x27;
			 TL1= 0x0f;
		}
		if(!mode && (TH1*256+TL1)>=999) 
		{
			TR1=0;	
			TH1= 0x03;
			TL1= 0xe7;
		}
		if(temp != P3_0)							
		{
			TR1=0;
			temp = P3_0;
			TH1=0;
			TL1=0;
			TR1=1;
		}
		quet();		 		
	}
}